package com.onlinefurnitureshop.order.controller;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.onlinefurnitureshop.customer.model.Customer;
import com.onlinefurnitureshop.order.model.Consignee;
import com.onlinefurnitureshop.order.service.OrderService;
import com.opensymphony.xwork2.ActionSupport;

public class AddConsigneeAction extends ActionSupport{
	private OrderService orderService;
	private Consignee consignee;
	private int consigneeId;	

	public Consignee getConsignee() {
		return consignee;
	}

	public void setConsignee(Consignee consignee) {
		this.consignee = consignee;
	}
	
	public OrderService getOrderService() {
		return orderService;
	}

	public void setOrderService(OrderService orderService) {
		this.orderService = orderService;
	}

	public int getConsigneeId() {
		return consigneeId;
	}

	public void setConsigneeId(int consigneeId) {
		this.consigneeId = consigneeId;
	}

	public String addConsignee(){
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();	
		Customer customer=(Customer) session.getAttribute("customer");
		consignee.setTheCustomer(customer);
		orderService.addConsignee(consignee);
			
		String runningAction=(String) session.getAttribute("runningAction");
		return runningAction;
	}
	
	public String toUpdateConsigneeView(){
		consignee=orderService.findConsigneeById(consigneeId);
		//System.out.println("----------toUpdateConsigneeView--------"+consignee.getConsigneeName());
		return "updateConsignee";
	}
	
	public String updateConsignee(){
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();	
		Customer customer=(Customer) session.getAttribute("customer");
		consignee.setTheCustomer(customer);
		orderService.updateConsignee(consignee);
		
		String runningAction=(String) session.getAttribute("runningAction");
		return runningAction;
	}
}
